package com.wakala.employment.fragment.other;

import android.annotation.SuppressLint;
import android.graphics.Typeface;
import android.os.Handler;
import android.os.Looper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.widget.ViewPager2;

import com.cy.tablayoutniubility.FragPageAdapterVp2;
import com.cy.tablayoutniubility.TabAdapter;
import com.cy.tablayoutniubility.TabLayoutScroll;
import com.cy.tablayoutniubility.TabMediatorVp2;
import com.cy.tablayoutniubility.TabViewHolder;
import com.leaf.library.StatusBarUtil;
import com.wakala.employment.R;
import com.wakala.employment.core.BaseFragment;
import com.wakala.employment.databinding.FragmentCommunicateRecordBinding;
import com.wakala.employment.fragment.message.InteractFragment;
import com.wakala.employment.fragment.message.MessageListFragment;
import com.xuexiang.xpage.annotation.Page;
import com.xuexiang.xpage.enums.CoreAnim;
import com.xuexiang.xui.widget.actionbar.TitleBar;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link CommunicateRecordFragment#} factory method to
 * create an instance of this fragment.
 */
@Page(anim = CoreAnim.none)
public class CommunicateRecordFragment extends BaseFragment<FragmentCommunicateRecordBinding> implements View.OnClickListener {
    private Handler mHandler = new Handler(Looper.getMainLooper());
    private ArrayList<Fragment> mFragments = new ArrayList<>();
    private final String[] mTitles = {
            "我联系的人", "谁联系过我"
    };

    @NonNull
    @Override
    protected FragmentCommunicateRecordBinding viewBindingInflate(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, boolean attachToRoot) {
        return FragmentCommunicateRecordBinding.inflate(inflater, container, attachToRoot);
    }

    @SuppressLint("UseCompatLoadingForDrawables")
    @Override
    protected TitleBar initTitle() {
        TitleBar titleBar = super.initTitle();
        titleBar.setTitle("沟通记录");
        titleBar.setTitleColor(R.color.black);
        titleBar.setTitleColor(R.color.black);
        titleBar.setLeftTextColor(R.color.black);
        titleBar.setLeftImageDrawable(getResources().getDrawable(R.drawable.icon_arrow_back));
        titleBar.setBackgroundResource(R.color.xui_config_color_light);//设置标题栏背景
        StatusBarUtil.setDarkMode(requireActivity());
        //设置状态栏背景颜色，如果设置为 Color.TRANSPARENT 将会隐藏状态栏
        requireActivity().getWindow().setStatusBarColor(getResources().getColor(R.color.xui_config_color_light));
        return titleBar;
    }



    @Override
    protected void initViews() {
        mFragments.add(CommunicateMeRecordFragment.newInstance("title",mTitles[0]));
        mFragments.add(CommunicateWhoRecordFragment.newInstance("title",mTitles[1]));

        ViewPager2 viewPager2 = findViewById(R.id.view_pager);
        viewPager2.setUserInputEnabled(false);
        TabLayoutScroll tabLayoutLine = findViewById(R.id.tablayout);
        FragPageAdapterVp2<String> fragmentPageAdapter = new FragPageAdapterVp2<String>(this) {

            @Override
            public Fragment createFragment(String bean, int position) {
                return mFragments.get(position);
            }

            @Override
            public void bindDataToTab(TabViewHolder holder, int position, String bean, boolean isSelected) {
                TextView textView = holder.getView(R.id.tv);
                if (isSelected) {
                    textView.setTextColor(getResources().getColor(R.color.xui_config_color_75_pure_black));
                    textView.setTextSize(16);
                    textView.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
                } else {
                    textView.setTextColor(getResources().getColor(R.color.xui_config_color_50_pure_black));
                    textView.setTextSize(16);
                    //textView.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
                    textView.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
                }
                textView.setText(bean);
            }

            @Override
            public int getTabLayoutID(int position, String bean) {
                return R.layout.item_tab;
            }
        };
        TabAdapter<String> tabAdapter = new TabMediatorVp2<String>(tabLayoutLine, viewPager2).setAdapter(fragmentPageAdapter);

        List<String> list = new ArrayList<>();
        list.add("我联系过的人");
        list.add("谁联系过我");
        fragmentPageAdapter.add(list);
        tabAdapter.add(list);
    }

    @Override
    protected void initListeners() {
        super.initListeners();
    }

    @Override
    public void onClick(View view) {

    }



}